package com.hnichr.ump.schedule.job.talent.library;

import com.hnichr.ump.common.schedule.dto.RunResultDTO;
import com.hnichr.ump.common.schedule.entity.ScheduleDesk;
import com.hnichr.ump.common.talent.library.service.SyncService;
import com.hnichr.ump.schedule.job.AbstractJob;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

@Component
public class SyncHuanghehrResumeJob extends AbstractJob {

    private static final Logger logger = LoggerFactory.getLogger(SyncHuanghehrResumeJob.class);

    @Autowired
    private SyncService syncService;

    @Override
    public String getScheduleName() {
        return "SyncHuanghehrResume";
    }

    @Override
    public boolean doRunCheck(ScheduleDesk scheduleDesk) {
        return DateUtils.addDays(DateUtils.truncate(scheduleDesk.getScheduleTime(),Calendar.DAY_OF_MONTH),1).compareTo(DateUtils.truncate(new Date(),Calendar.DAY_OF_MONTH))<0;
    }

    @Override
    public RunResultDTO doRun(ScheduleDesk scheduleDesk) {
        logger.info("SyncHuanghehrResumeJob::doRun 开始执行");
        String date = DateFormatUtils.format(scheduleDesk.getScheduleTime(),"yyyyMMdd");
        return syncService.syncHuanghehrResume(date);
    }

    @Override
    public Date getNextScheduleTime(ScheduleDesk scheduleDesk) {
        Date date = DateUtils.addDays(scheduleDesk.getScheduleTime(),1);
        return DateUtils.truncate(date, Calendar.DAY_OF_MONTH);
    }
}
